package com.regentsoft.cloudback.util;

import java.util.Random;
import java.util.UUID;

/**
 * 
 * @author czd
 *
 * @date 2017年11月25日
 *
 * @version 1.0
 */
public class CodeUtil {
	public static String genCodes(int length) {
			String val = "";
			Random random = new Random();
			for (int i = 0; i < length; i++) {
				String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; // 输出字母还是数字

				if ("char".equalsIgnoreCase(charOrNum)) // 字符串
				{
					int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; // 取得大写字母还是小写字母
					val += (char) (choice + random.nextInt(26));
				} else if ("num".equalsIgnoreCase(charOrNum)) // 数字
				{
					val += String.valueOf(random.nextInt(10));
				}
			}
			val = val.toLowerCase();
			
			return val;

	}

	public static String genTOKEN(){
        return UUID.randomUUID().toString().replaceAll("-","");
    }
	
	public static void main(String[] args) {
	    String results=genCodes(6);
	    System.out.println(results);
	  }
}
